﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using WXYW.DAL;
using WXYW.BLL;

namespace WXYW
{
    public partial class ForgetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GetPasswordButton_Click(object sender, EventArgs e)
        {
            try
            {
                UserService userService = new UserService();
                WXYW.DAL.User userEntity = userService.GetUserByName(UserNameTxtBox.Text);

                if (userEntity != null)
                {
                    string emailBody = string.Format(WebConfigurationManager.AppSettings["SendPasswordEmail"], userEntity.UserName, userEntity.UserPassword);
                    EmailService.SendEmail(userEntity.UserEmail, "用户密码", emailBody);
                }
                else
                {
                    MsgLbl.Text = "系统中不存在你的用户名，请检查拼写是否正确。";
                }
            }
            catch (Exception ex)
            {
                MsgLbl.Text = string.Format("系统错误：{0}", ex.Message);
            }
        }
    }
}
